<div class="container-fluid suredy-form" style="padding-top: 0">
	<div class="row">	
	<form name="form" id="form">
	<#if resource??>
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">资源名称</div>
				<input type="text" class="form-control" name="name" readonly="readonly" value="${resource.name}" />
			</div>
		</div>	
		<div class="form-group">	
			<div class="input-group">
				<div class="input-group-addon">资源标识</div>
				<input type="text" class="form-control" name="url" readonly="readonly" value="${resource.uri}" />
				<input type="hidden"  name="id" value="${resource.id}" />
			</div>	
		</div>
	</#if>	
		<div class="form-group">
			<table  class="table table-striped table-bordered table-hover">						
				<tr>
					<th>角色代码</th>
					<th>角色名</th>
					<th>完整角色名</th>
					<#if actions??> <#list actions as action>
					<th style="width:80px; text-align:center;">${action.getDescription()}</th>
					</#list></#if>
				</tr>
				<#if roles??> <#list roles as role>
				<tr>
					<td>${role.groupName}</td>
					<td>${role.mc}</td>
					<td>${role.qc}</td>
					<#if actions??> <#list actions as action>
						<#-- permissionId -->
						<#if permissions??><#list permissions as permission>
				            <#if permission.action == action.getAction()>
				                <#assign permissionId = permission.id />
				                <#break>
				            </#if>
				        </#list></#if>
				        <#-- checked -->
				        <#assign isChecked="" />
				        <#if rolePermissions??><#list rolePermissions as rp>
				        	<#if permissionId?? && (rp.roleId==role.id) && (rp.rolePermission.id == permissionId) >
				        	    <#assign isChecked="checked=\"checked\"" />
				        	    <#break>
				        	</#if>
				        </#list></#if>
				        
						<td class="text-center"><input type="checkbox" name="${action}" value="${role.id}" ${isChecked} /></td>
					</#list></#if>
				</tr>
				</#list></#if>
			</table>
		</div>
		<div class="text-center">
			<button class="btn btn-info" id="btn-save" type="button">
				<i class="icon-save"></i>
				保存
			</button>
		</div>	
	</form>	
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
		$('#btn-save').click(function() {
			$.ajax({
				type : 'POST',//发送请求的方式
				url : 'resource2role-save.do',
				data : $('#form').serialize(),
				dataType : "json",//文件类型
				cache : false,
				timeout : 60000,//超时设置，单位为毫秒
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("未知错误,提交信息失败...");
				},
				success : function(result) {
					alert(result==1 ? '已保存' : '保存失败');
				}
			});		
		});	
	});
</script>	
